<template>
    <section class="assessmentIndex">
<!--        <div  v-if="!(this.currentTask.hasCheckTask)">暂无任务</div>-->
        <el-form v-loading="formLoad" v-if="this.currentTask.hasCheckTask" class="demo-form-inline  common-textarea EconomicIncome" ref="reviewForm" :model="reviewForm" label-width="240px" :inline="true" >
            <el-form-item label="本年度村集体经济收入" prop="currentYearEconomicIncome" :rules="{required: true, message: '本年度村集体经济收入不能为空', trigger: 'blur'}" >
                <el-input type="text" v-model="reviewForm.currentYearEconomicIncome" :rows="1" :disabled="!disabled" ></el-input>
            </el-form-item>
            <br>
            <el-form-item label="上年度村集体经济收入" prop="lastYearEconomicIncome" :rules="{required: true, message: '上年度村集体经济收入不能为空', trigger: 'blur'}">
                <el-input type="text" :rows="2"  v-model="reviewForm.lastYearEconomicIncome" :disabled="!disabled"></el-input>
            </el-form-item>
            <br>
            <el-form-item label="年度村集体经济收入佐证" prop="incomeSupportDoc" :rules="{required: true, message: '年度村集体经济收入佐证不能为空', trigger: 'blur'}">
                <FileUpload  :value="reviewForm.incomeSupportDoc" :disabled="!disabled" @getValue="reviewForm.incomeSupportDoc = $event" style="width: 150px;"></FileUpload>
            </el-form-item>
            <el-form-item v-for="item in gradeForm" :label="item.quotaName">
                <el-input type="text" :rows="2"  v-model="item.score" :disabled="!disabled"></el-input>
            </el-form-item>
            <el-form-item label="人居环境是否通过检查" prop="hasPass" :rules="{required: true, message: '人居环境是否通过检查', trigger: 'blur'}">
                <el-input v-model="reviewForm.hasPass" :disabled="!disabled"></el-input>
            </el-form-item>
            <el-form-item v-for="item in scoreForm" :label="item.quotaName" >
                <el-input v-model="item.score" :disabled="!disabled"></el-input>
            </el-form-item>
            <el-form-item label="人居佐证" prop="environmentSupportDoc" :rules="{required: true, message: '人居佐证', trigger: 'blur'}">
                <FileUpload  :value="reviewForm.environmentSupportDoc" :disabled="!disabled" @getValue="reviewForm.environmentSupportDoc = $event" style="width: 150px;"></FileUpload>
            </el-form-item>
            <div style="text-align: center" v-if="disabled">
                <el-button type="primary"  @click="save()">保存</el-button>
            </div>

        </el-form>
    </section>
</template>

<script>
    import FileUpload from '@/components/FileUpLoad';
    import md5 from '@/utils/md5';
    export default {
        name: "AssessmentIndex",
        props:{
            currentTask:{
                type:Object,
            },
            currentCun:{
                type:String
            },
            currentStatus:{
                type:Object
            }
        },
        data(){
            return{
                reviewForm : {},
                gradeForm : {},
                formLoad : false,
                disabled:false,
                scoreForm:[],
            }
        },
        watch:{
            'currentCun':{
                handler:function(){
                    this.getTargetDetail(this.currentCun);
                }
            },
            'currentStatus':{
                handler:function(){
                    this.disabled = this.currentTask.hasCheckTask&&this.currentStatus.status==0;
                }
            },
            'currentTask':{
                handler:function(){
                    this.disabled = this.currentTask.hasCheckTask&&this.currentStatus.status==0;
                }
            }

        },
        components:{
            FileUpload,
        },
        mounted() {},
        methods:{
             getTargetDetail(districtId){
                 this.formLoad = true;
                 //初始化基础数据
                 this.$http('POST',`identity/detectionIndex/list`,{taskId:this.currentTask.taskId,districtId: districtId},false).then(data=>{
                        this.reviewForm = data[0];
                        this.formLoad = false;
                        this.$http('get',`identity/kPITownQuota/getAllByVillageId/${districtId}/0301`,false).then(data=>{
                             this.gradeForm = data;
                             this.formLoad = false;
                        }).catch(()=>{
                             this.formLoad = false;
                        });
                         this.$http('GET',`identity/kPITownQuota/getAllByVillageId/${districtId}/0305`,false).then(data=>{
                             this.scoreForm = data;
                             this.formLoad = false;
                         }).catch(()=>{
                             this.formLoad = false;
                         });
                    }).catch(()=>{
                     this.formLoad = false;
                    });
                 //初始化村
             },
             save(){
                 this.formLoad = true;
                 this.$http('PUT',`identity/detectionIndex/${this.reviewForm.id}id`,this.reviewForm,false).then(data=>{
                     this.$http('post',`identity/kPITownQuota/updateStatisticsQoutaScore`,this.gradeForm,false).then(data=>{
                         this.formLoad = false;
                     }).catch(()=>{
                         this.formLoad = false;
                     });
                     this.$http('POST',`identity/kPITownQuota/updateStatisticsQoutaScore`,this.scoreForm,false).then(data=>{
                         this.formLoad = false;
                         this.$message({
                             type:'success',
                             message:'保存成功'
                         })
                     }).catch(()=>{
                         this.formLoad = false;
                     })
                 }).catch(()=>{
                     this.formLoad = false;
                 });
             }
        }
    }

</script>

<style>
    .save {
        margin-left: 250px;
       text-align: center;
    }
</style>

<style scoped>
  .assessmentIndex .EconomicIncome {
      width: 600px!important;
      text-align: left;
  }
</style>
